package com.example.ui.learn.util;

import java.io.File;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.huashangapp.R;
import com.example.net.NetRequest;
import com.example.util.AsyncLoadImage;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;




public class MyListViewAdapter1 extends BaseAdapter{
	private LayoutInflater inflater;
	private ArrayList<CurriculumCenter> list;
	private AsyncLoadImage asyncLoadImage;
	public MyListViewAdapter1(Context mContext,ArrayList<CurriculumCenter> list,AsyncLoadImage ali){
		inflater = LayoutInflater.from(mContext);
		this.list=list;
        this.asyncLoadImage=ali;
	}
	public ArrayList<CurriculumCenter> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<CurriculumCenter> list) {
		if (list == null) {
			this.list = new ArrayList<CurriculumCenter>();
		}
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		convertView=null;
		CurriculumCenter cc=list.get(position);
		final String url =NetRequest.requesthttp+cc.getThumb();
		final ImageView imageView;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.item01_listview_item, null);
			holder = new Holder();
        	imageView = (ImageView)convertView.findViewById(R.id.item01_list_img);
			holder.textTitle = (TextView) convertView.findViewById(R.id.item01_list_text_title);
			holder.textNum = (TextView) convertView.findViewById(R.id.item01_list_text_num);
        	convertView.setTag(holder);
        } else {
        	imageView = (ImageView)convertView.findViewById(R.id.item01_list_img);
            holder = (Holder) convertView.getTag();
        }
		imageView.setTag(url);	
		
		asyncLoadImage.imageLoader.displayImage(url, imageView,asyncLoadImage.options);
			imageView.setTag(url);
		
		
		holder.textTitle.setText(cc.getTitle());
		
		holder.textNum.setText("( "+cc.getTotalCourse()+"个课程)");
		return convertView;
	}
	
	class Holder{
    	
    	TextView textTitle;
    	TextView textNum;
    }
	
	
}
